#include <iostream>
#include "evnetplus/invoke_timer.h"
#include "evnetplus/event_loop_thread.h"
#include "evnetplus/event_watcher.h"


#if 0

int main(int argc, char const *argv[])
{
    evnetplus::EventLoopThread loopthread;
    loopthread.Start(true);

    // evnetplus::EventLoopThread timer2loopthread;
    // timer2loopthread.Start(true);

    evnetplus::InvokeTimerPtr timer1;
    timer1 = evnetplus::InvokeTimer::Create(loopthread.loop(), evnetplus::Duration(1.0F), []{
        std::cout << "This is timer 1" << std::endl;
    }, true);
    timer1->Start();

    // evnetplus::InvokeTimerPtr timer2;
    // timer2 = evnetplus::InvokeTimer::Create(timer2loopthread.loop(), evnetplus::Duration(1.0F), []{
    //     std::cout << "This is timer 2" << std::endl;
    //     sleep(5);
    // }, true);
    // timer2->Start();

    bool bEnableStop = false;
    evnetplus::SignalEventWatcher signalWatcher(SIGINT, loopthread.loop(), [&bEnableStop](){
        std::cout << "atched signal" << std::endl;
        bEnableStop = true;
    });
    signalWatcher.Init();
    signalWatcher.AsyncWait();

    while (!bEnableStop) {
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }



    return 0;
}

#endif

#include "evnetplus/event_loop_thread_pool.h"

using namespace evnetplus;

int main(int argc, char const *argv[])
{
    EventLoop baseloop;
    EventLoopThreadPool tpool(&baseloop, 4);
    tpool.Start(true);

    evnetplus::InvokeTimerPtr timer1;
    timer1 = evnetplus::InvokeTimer::Create(tpool.GetNextLoop(), evnetplus::Duration(1.0F), []{
        std::cout << "This is timer 1" << std::endl;
    }, true);
    timer1->Start();

    evnetplus::InvokeTimerPtr timer2;
    timer2 = evnetplus::InvokeTimer::Create(tpool.GetNextLoop(), evnetplus::Duration(1.0F), []{
        std::cout << "This is timer 2" << std::endl;
        sleep(5);
    }, true);
    timer2->Start();

    bool bEnableStop = false;
    evnetplus::SignalEventWatcher signalWatcher(SIGINT, tpool.GetNextLoop(), [&bEnableStop](){
        std::cout << "atched signal" << std::endl;
        bEnableStop = true;
    });
    signalWatcher.Init();
    signalWatcher.AsyncWait();

    while (!bEnableStop) {
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }

    tpool.Stop(true);

    return 0;
}

